<?php
 class LoginAction extends Action{
 	public function index(){
 		$this->display();
 	}
 	/**
 	 * 验证码
 	 */
 	public function verify(){
 		import('ORG.Util.Image');
		Image::buildImageVerify();
 	}
 	/**
 	 * 登录验证
 	 */
 	public function check(){
 		if(!$this->isAjax()){
 			halt('页面不存在');
 		}
 		$mark=(int)$_POST['mark'];
 		$username=htmlspecialchars($_POST['username']);
 		$pwd=md5($_POST['pwd']);
 		$verify=md5($_POST['verify']);
 		if($verify!=$_SESSION['verify']){
 			echo 0;
 			die;
 		}
 		$db=M('user');
 		$result=$db->where(array('username'=>$username))->find();
 		if($result){
 			$password=$db->where(array('username'=>$username))->getField('password');
 			if($pwd!=$password){
 				echo 1;
 				die;
 			}
 		}else{
 			echo 1;
 			die;
 		}
 		$_SESSION['uid']=$result['id'];
 		$_SESSION['username']=$username;
 		if($mark==1){
 			echo 3;
 		}else{
 			echo 2;
 		}
 	}
 	public function LoginOut(){
 		unset($_SESSION['username']);
 		unset($_SESSION['uid']);
 		header('location:../');

 	}
 }
?>